/* vim: set expandtab shiftwidth=4: -*- mode: c++; c-basic-offset: 4; tab-width: 8; indent-tabs-mode: nil -*-
qRPG
An RPG written to test Qt's Graphics View framework
Copyright (C) 2006 Wesley Crossman
Email: wesley@crossmans.net

You can redistribute and/or modify this software under the terms of the GNU
General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA */

#ifndef BOARDCHARACTER_H
#define BOARDCHARACTER_H

#include <QtCore>
class QGraphicsPixmapItem;
class GameBoardScene;
class QKeyEvent;
class QPixmap;
class GameBoardScene;
class LightTileGenerator;
class GameCharacter;

class GameItem : public QObject {
Q_OBJECT
protected:
    int x, y;
    QPointer < GameItem > parent;
    QList < GameItem * > children;
public:
    QGraphicsPixmapItem *item;
    GameBoardScene *scene;
    GameItem(int x, int y, GameBoardScene *scene);
    virtual ~GameItem();
    int getX() {assert(!hasParent()); return x;}
    int getY() {assert(!hasParent()); return y;}
    QPoint getPos() {return QPoint(x, y);}
    virtual void setX(int x);
    virtual void setY(int y);
    virtual void setPos(QPoint pos) {setX(pos.x()); setY(pos.y());}
    virtual bool isBlocking() {return false;}
    virtual QStringList getFunctions();
    virtual bool callFunction(GameCharacter *character, QString function);
    virtual void tick() {}
    
    // * code for item containment *
    GameItem *getParent() {return parent;}
    bool hasParent() {return parent;}
    QList < GameItem * > getChildren() {return children;}
    //drop child -- call child's /getOut/
    virtual void loseItem(GameItem *item);
    //get acquired by new parent -- call parent's /forceAddChildToList/
    virtual void getIntoItem(GameItem *item);
    //add to list without telling child
    void addChildToList(GameItem *);
    //add to list without telling child
    void removeChildFromList(GameItem *);
    //unset parent without telling parent
    void setParent(GameItem *);
public slots:
    //drop children -- call /loseItem/ for each
    virtual void loseAll();
    //disconnect from parent -- call parent's /forceRemoveChildFromList/
    virtual void getOut();
signals:
    void contentsChanged();
};

class Potion : public GameItem {
Q_OBJECT
public:
    Potion(int x, int y, GameBoardScene *scene);
    virtual QStringList getFunctions();
    virtual bool callFunction(GameCharacter *character, QString function);
};

class Scroll : public GameItem {
Q_OBJECT
protected:
    int stage;
    GameCharacter *caller;
protected slots:
    void finish();
public:
    static QStringList scrollText;
    Scroll(int x, int y, GameBoardScene *scene);
    virtual QStringList getFunctions();
    virtual bool callFunction(GameCharacter *character, QString function);
};

class Bag : public GameItem {
Q_OBJECT
public:
    Bag(int x, int y, GameBoardScene *scene);
    virtual QStringList getFunctions();
    virtual bool callFunction(GameCharacter *character, QString function);
};

class GameCharacter : public GameItem {
Q_OBJECT
public:
    GameCharacter(int x, int y, GameBoardScene *scene);
    void ensureVisible();
    virtual bool isTileClear(int x, int y);
    bool isTileClear(QPoint p) {return isTileClear(p.x(), p.y());}
    virtual bool isValidPath(int x, int y);
    bool isValidPath(QPoint p) {return isValidPath(p.x(), p.y());}
    virtual bool isTileFightable(int x, int y);
    bool isTileFightable(QPoint p) {return isTileFightable(p.x(), p.y());}
    bool isBlocking() {return true;}
};

class Enemy : public GameCharacter {
Q_OBJECT
public:
    Enemy(int x, int y, GameBoardScene *scene);
    void tick();
};

class Hero : public GameCharacter {
Q_OBJECT
protected:
    LightTileGenerator *lightTiles;
    QPixmap *blackTile;
public:
    Hero(int x, int y, GameBoardScene *scene);
    void keyPressed(QKeyEvent *);
    void updateLighting();
signals:
    void moved();
};

#endif

